/*
 * Created by JFormDesigner on Mon Jun 03 16:55:49 EDT 2013
 */

package PartsLookUp;

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;

/**
 * @author Jason Chi
 */
public class PartsLookupByPL extends JFrame {
    Statement stmt;
    Statement stmtbl;

    public PartsLookupByPL() {
        initComponents();
    }

    private void partsLinkNumActionPerformed(ActionEvent e) {
        System.out.println(e);

        initializeDBLi();
        try{
            String queryString = "select tblinventory.categoryid, tblinventory.[part#],tblinventory.lpp, tblinventory.unitcost, tblinventory.sellingprice, tblinventory.cif"+
                    "from tblinventory"+
                    "where tblinventory.partslink ="+e;

            ResultSet resultSet=stmt.executeQuery(queryString);

            if (resultSet.next()){
                cat.setText(resultSet.getString("tblinventory.categoryid"));
//                String cat1 = resultSet.getString(1);
//                String partnum1 = resultSet.getString(2);
//                String lpp1 = resultSet.getString(3);
//                String unitcost1 = resultSet.getString(4);
//                String sellingprice1 = resultSet.getString(5);
//                String cif1 = resultSet.getString(6);


            }else {
                JOptionPane.showMessageDialog(null,"Not found");
            }

        }catch (SQLException ex){
            ex.printStackTrace();
        }
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        // Generated using JFormDesigner Evaluation license - Jason Chi
        label1 = new JLabel();
        partsLinkNum = new JTextField();
        panel1 = new JPanel();
        label2 = new JLabel();
        cat = new JTextField();
        label3 = new JLabel();
        partNum = new JTextField();
        label4 = new JLabel();
        lpp = new JTextField();
        label5 = new JLabel();
        unitPrice = new JTextField();
        label6 = new JLabel();
        sellingPrice = new JTextField();
        label7 = new JLabel();
        cif = new JTextField();
        scrollPane1 = new JScrollPane();
        jtable1 = new JTable();

        //======== this ========
        Container contentPane = getContentPane();
        contentPane.setLayout(new GridBagLayout());
        ((GridBagLayout)contentPane.getLayout()).columnWidths = new int[] {0, 86, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 215, 0};
        ((GridBagLayout)contentPane.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0};
        ((GridBagLayout)contentPane.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
        ((GridBagLayout)contentPane.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

        //---- label1 ----
        label1.setText("Parts Lookup by PartsLink#");
        contentPane.add(label1, new GridBagConstraints(15, 0, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 5), 0, 0));

        //---- partsLinkNum ----
        partsLinkNum.setText("Enter Parts Link #");
        partsLinkNum.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                partsLinkNumActionPerformed(e);
            }
        });
        contentPane.add(partsLinkNum, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 5), 0, 0));

        //======== panel1 ========
        {

            // JFormDesigner evaluation mark
            panel1.setBorder(new javax.swing.border.CompoundBorder(
                new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
                    "JFormDesigner Evaluation", javax.swing.border.TitledBorder.CENTER,
                    javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12),
                    java.awt.Color.red), panel1.getBorder())); panel1.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});

            panel1.setLayout(new GridBagLayout());
            ((GridBagLayout)panel1.getLayout()).columnWidths = new int[] {0, 95, 0, 0, 0, 0, 0, 0, 0, 0, 0};
            ((GridBagLayout)panel1.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
            ((GridBagLayout)panel1.getLayout()).columnWeights = new double[] {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0E-4};
            ((GridBagLayout)panel1.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

            //---- label2 ----
            label2.setText("Category");
            label2.setLabelFor(cat);
            panel1.add(label2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 5), 0, 0));
            panel1.add(cat, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 5), 0, 0));

            //---- label3 ----
            label3.setText("DNK #");
            label3.setLabelFor(partNum);
            panel1.add(label3, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 5), 0, 0));
            panel1.add(partNum, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 5), 0, 0));

            //---- label4 ----
            label4.setText("Last Purchase Price");
            label4.setLabelFor(lpp);
            panel1.add(label4, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 5), 0, 0));
            panel1.add(lpp, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 5), 0, 0));

            //---- label5 ----
            label5.setText("Unit Cost");
            label5.setLabelFor(unitPrice);
            panel1.add(label5, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 5), 0, 0));
            panel1.add(unitPrice, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 5), 0, 0));

            //---- label6 ----
            label6.setText("Selling Price");
            label6.setLabelFor(sellingPrice);
            panel1.add(label6, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 5), 0, 0));
            panel1.add(sellingPrice, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 5), 0, 0));

            //---- label7 ----
            label7.setText("CIF");
            label7.setLabelFor(cif);
            panel1.add(label7, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 5), 0, 0));
            panel1.add(cif, new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 5, 5), 0, 0));
        }
        contentPane.add(panel1, new GridBagConstraints(1, 4, 15, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 5), 0, 0));

        //======== scrollPane1 ========
        {
            scrollPane1.setViewportView(jtable1);
        }
        contentPane.add(scrollPane1, new GridBagConstraints(16, 4, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0), 0, 0));
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    // Generated using JFormDesigner Evaluation license - Jason Chi
    private JLabel label1;
    private JTextField partsLinkNum;
    private JPanel panel1;
    private JLabel label2;
    private JTextField cat;
    private JLabel label3;
    private JTextField partNum;
    private JLabel label4;
    private JTextField lpp;
    private JLabel label5;
    private JTextField unitPrice;
    private JLabel label6;
    private JTextField sellingPrice;
    private JLabel label7;
    private JTextField cif;
    private JScrollPane scrollPane1;
    private JTable jtable1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables



    private void initializeDBLi() {

        try {

            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

            //Connection to Hicksville
            String dataSourceName = "dbLI";
            String dbURL = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName).toString();
            Connection connection = DriverManager.getConnection(dbURL, "", "");
            stmt = connection.createStatement();

        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    private void initializeDBbl() {

        try {


            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");


            //Connection to Brooklyn
            String dataSourceNameBL = "dbBL";
            String dbURLBL = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceNameBL).toString();
            Connection connectionBL = DriverManager.getConnection(dbURLBL, "", "");
            stmtbl = connectionBL.createStatement();

        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}